﻿using System;
using System.Collections.Generic;
using Jayden.Dll.Web.Enums;
using Jayden.Dll.Web.HtmlControls.Descriptions;
using Jayden.Dll.Web.HtmlControls.Generics;
using Jayden.Dll.Web.HtmlControls.Interfaces;

namespace Jayden.Dll.Web.HtmlControls
{
	public class Td : HtmlElement, WithColSpan, WithRowSpan
	{
		public Td() : base(TdDescription.Instance) { }
		public Td(string text, bool htmlEncode = true)
			: this()
		{
			if (text != null)
				AddText(text, htmlEncode);
		}

		public uint? ColSpan { get { return GetAttributeUint("colspan"); } set { SetAttribute("colspan", value); } }
		public uint? RowSpan { get { return GetAttributeUint("rowspan"); } set { SetAttribute("rowspan", value); } }
		public string Headers { get { return this["headers"]; } set { this["headers"] = value; } }
	}
	public class TdDescription : HtmlElementDescription
	{
		public static readonly TdDescription Instance = new TdDescription();
		private TdDescription() : base("td", HtmlVersion.Html4, true, true) { }
		public override Type ControlType { get { return typeof(Td); } }
		public override string Description { get { return "data cell in a table."; } }
		public override IEnumerable<HtmlElementDescription> PermittedParents { get { yield return TrDescription.Instance; } }
	}
	public class Th : HtmlElement, WithColSpan, WithRowSpan
	{
		public Th() : base(ThDescription.Instance) { }
		public Th(string text, bool htmlEncode = true)
			: this()
		{
			if (text != null)
				AddText(text, htmlEncode);
		}

		public string Scope { get { return this["scope"]; } set { this["scope"] = value; } }
		public uint? ColSpan { get { return GetAttributeUint("colspan"); } set { SetAttribute("colspan", value); } }
		public uint? RowSpan { get { return GetAttributeUint("rowspan"); } set { SetAttribute("rowspan", value); } }
		public string Headers { get { return this["headers"]; } set { this["headers"] = value; } }
	}
	public class ThDescription : HtmlElementDescription
	{
		public static readonly ThDescription Instance = new ThDescription();
		private ThDescription() : base("th", HtmlVersion.Html4, true, true) { }
		public override Type ControlType { get { return typeof(Th); } }
		public override string Description { get { return "header cell in a table."; } }
		public override IEnumerable<HtmlElementDescription> PermittedParents { get { yield return TrDescription.Instance; } }
	}
}
